/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License. You may obtain a copy of the License at
	http://www.mozilla.org/MPL/
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import com.bourre.core.HashCodeFactory;
import com.bourre.utils.ClassUtils;

import fever.data.libs.BitmapLibLocator;
import fever.utils.Stringifier;

/**
 * Look'n Feel definition.
 * 
 * <p>Example using <strong>AsWing</strong> Look'n Feel.
 * {@code
 *   var at : ThemeLocator = ThemeLocator.getInstance();
 *   at.register( 'Office 2003', new Office2003LAF() );
 *   at.register( 'WinXP 2003', new WinXPLAF() );
 *   at.addEventListener( ThemeLocator.onChangeEVENT, this, _onUIUpdate );
 *   at.load( 'WinXP 2003' );
 * }
 * 
 * <p>Look and Feel is really apply using custom process.<br />
 * Associates {@code Command} to 
 * {@link fever.events.FeverEventList#onApplyLookAndFeelEVENT} event type.<br />
 * A concrete command example is available in {@link fvaswing.commands.FvApplyLookAndFeel}
 * 
 * @see fever.app.theme.ThemeLocator
 * @see fvaswing.components.FvThemeChooser
 * 
 * @author Romain Ecarnot
 */
class fever.app.theme.Theme
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private var _name : String;
	private var _instanceName : String;
	
	private var _previewLink : String;
	
	
	//-------------------------------------------------------------------------
	// Public Properties
	//-------------------------------------------------------------------------
	
	/** Bitmaps repository for theme image preview. */
	public static var PREVIEW_REPOSITORY : String = BitmapLibLocator.DEFAULT;
	
		
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 * 
	 * @param lafName Registration name
	 * @param lafInstance Concrete Look and Feel class
	 * @param ( optional ) URL link to theme preview image
	 */
	public function Theme( lafName : String, lafInstance : Object, preview : String )
	{
		_name = lafName;
		_instanceName = ClassUtils.getFullyQualifiedClassName( lafInstance );
		_previewLink = preview;
	}
	
	/**
	 * Returns Look'n Feel name.
	 */
	public function getName() : String
	{
		return _name;	
	}
	
	/**
	 * Returns Look'n Feel instance name.
	 */
	public function getInstanceName() : String
	{
		return _instanceName;	
	}
	
	/**
	 * Returns Look'n Feel class.
	 * 
	 * <p>Return type is not typed to allow custom Look and Feel 
	 * definition ( LookAndFeel instance for AsWing for example )
	 */
	public function getClass() : Object
	{
		return HashCodeFactory.buildInstance( _instanceName );	
	}
	
	/**
	 * Sets preview image url.
	 */
	public function setPreview( previewLink : String ) : Void
	{
		_previewLink = previewLink; 
	}
	
	public function hasPreview() : Boolean
	{
		return ( BitmapLibLocator.isFullQualifiedBitmapExist( _previewLink + '@' + PREVIEW_REPOSITORY ) );	
	}
	
	/**
	 * Returns Look'n Feel image preview.
	 */
	public function getPreview() : String
	{
		return _previewLink;
	}
	
	/**
	 * Returns string representation.
	 */
	public function toString() : String
	{
		return Stringifier.parse( this );
	}
}